package iddss;

import java.io.IOException;
import java.net.ServerSocket;
import plugin.ThreadLoadPlugin;


/**
 *
 * @author ZeM
 */
public class client {

    public void Start() {
         //loading autostart plugins in threads
            for (int k=0; k<Parameters.AutostartPluginsList.length; k++){
                if (Parameters.AutostartPluginsList[k]!=null && Parameters.AutostartPluginsList[k].length()>0){
            ThreadLoadPlugin tlp=new ThreadLoadPlugin();
            tlp.PluginName=Parameters.AutostartPluginsList[k];
            new Thread(tlp).start();
                }
            }


        System.out.println("Welcome to IDDS");
        ServerSocket ss;
        try {

            ss = new ServerSocket(Parameters.port);
           
            while (true) {
                try {
                    //need to check if socket is not used
                    int p = 0;
                    boolean found = false;
                    do {
                        if (!Parameters.connection_is_used[p]) {
                            found = true;
                        } else {
                            p++;
                        }
                    } while (p < Parameters.connection_is_used.length & !found);


                    Parameters.connection[p] = new ClientWorker(ss.accept(), p);
                    Thread t = new Thread(Parameters.connection[p]);
                    t.start();
                } catch (IOException e) {
                    System.out.println("Accept failed");

                }
            }



        } catch (IOException ex) {
        }



    }
}

